package com.lanou3g.ptp.warning;

import com.lanou3g.ptp.warning.job.WarningJob;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.annotation.PostConstruct;

@SpringBootApplication
@ComponentScan(lazyInit = true)
public class PtpWarningServiceApplication {
    @Autowired
    private Scheduler scheduler;

    public static void main(String[] args) {
        SpringApplication.run(PtpWarningServiceApplication.class, args);
    }

    @PostConstruct
    public void post() throws SchedulerException {
        String warningJobClassName = WarningJob.class.getName();
        scheduler.start();
        JobDetail warningJob = JobBuilder.newJob(WarningJob.class).withIdentity(warningJobClassName).build();
        CronScheduleBuilder schedule0h0m =
                CronScheduleBuilder.dailyAtHourAndMinute(9, 46).withMisfireHandlingInstructionDoNothing();
        Trigger trigger =
                TriggerBuilder.newTrigger().withIdentity(warningJobClassName).withSchedule(schedule0h0m).build();
        scheduler.scheduleJob(warningJob, trigger);
    }

}
